'use strict'

 const { DataTypes, Model, Op } = require('../../azeroth').sequelize;
 class PanelInfo extends Model { }

  const initPanelData = (sequelize_aim) => {
    PanelInfo.init(
        {
            uid: {
                field: 'uid',
                type: DataTypes.INTEGER,
                allowNull: false,
                primaryKey: true,
                autoIncrement: true
            },
            job_id: {
                field: 'job_id',
                type: DataTypes.INTEGER,
                allowNull: false,
                primaryKey: true,
                autoIncrement: false
            },
            panel_id: {
                field: 'panel_id',
                type: DataTypes.STRING
            },
            flaw_count: {
                field: 'flaw_count',
                type: DataTypes.INTEGER
            },
            is_ok: {
                field: 'is_ok',
                type: DataTypes.INTEGER
            },
            length_md: {
                field: 'length_md',
                type: DataTypes.INTEGER
            },
            length_cd: {
                field: 'length_cd',
                type: DataTypes.INTEGER
            },
            save_path: {
                field: 'save_path',
                type: DataTypes.STRING
            },
            gen_time: {
                field: 'gen_time',
                type: DataTypes.BIGINT
            },
            gen_time_str: {
                field: 'gen_time_str',
                type: DataTypes.STRING
            },
            detectParam: {
                field: 'detectParam',
                type: DataTypes.TEXT
            },
            checked: {
                field: 'checked',
                type: DataTypes.INTEGER
            },
         },
         {
             freezeTableName: true,
             sequelize: sequelize_aim,
             modelName: 'panel',
             timestamps: false
         }
     )
  }

  PanelInfo.uploadPanelInfo = async (data) => {
     let res = await PanelInfo.bulkCreate([...data], {updateOnDuplicate: ['uid', 'panel_id', 'job_id', 'flaw_count', 'is_ok', 'length_md', 'length_cd']});
     return res;
 }

 module.exports = {
     PanelInfo,
     initPanelData
 };